package com.cheng.service.impl;

import java.util.List;

import javax.ws.rs.QueryParam;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cheng.dao.CustomerRespository;
import com.cheng.domain.Customer;
import com.cheng.service.CustomerService;

@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {

	@Autowired
	private CustomerRespository customerRespository;
	@Override
	public List<Customer> getNoassociationCustomer() {
		return customerRespository.findByFixedAreaIdIsNull();
	}

	@Override
	public List<Customer> getAssociationCustomer(String fixedareaid) {
		return customerRespository.findByFixedAreaId(fixedareaid);
	}

	@Override
	public void updateAssociation(String fixedareaid,String customerids) {
		
		customerRespository.clearFixedareaid(fixedareaid);
		if (",".equals(customerids)) {
			return;
		}else{
			String[] ids = customerids.split(",");
			for (String str : ids) {
				Integer id = Integer.parseInt(str);
				customerRespository.associationCustomer(fixedareaid,id);
			}
		}
	}

	@Override
	public void registeCustomer(Customer customer) {
		customerRespository.save(customer);
	}

	@Override
	public void updateCustomer(String telephone) {
		customerRespository.updataCustomer(telephone);
	}

	@Override
	public Customer getCustomer(String telephone) {
		
		return customerRespository.getByTelephone(telephone);
	}

	@Override
	public String getFixedareaByaddress(String address,Integer id) {
		 String fixedareaid = customerRespository.findFixedareaByaddress(address,id);
		 return fixedareaid;
	}

}
